package com.hctg.forced2sleep.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.actor.myandroidframework.widget.BaseItemDecoration;
import com.blankj.utilcode.util.SizeUtils;
import com.hctg.forced2sleep.adapter.EditMinuteActivityAdapter;
import com.hctg.forced2sleep.databinding.ActivityEditMinuteBinding;
import com.hctg.forced2sleep.dialog.IntEditDialog;
import com.hctg.forced2sleep.dialog.VipBuyDialog;

import java.util.List;

/**
 * description: 首页 -> 禅定时长设置 -> 更多时间
 * company    :
 * @author    : ldf
 * date       : 2024/12/1 on 14:00
 */
//rename from EditTimeBi
public class EditMinuteActivity extends BaseActivity<ActivityEditMinuteBinding> {

    private final EditMinuteActivityAdapter mAdapter = new EditMinuteActivityAdapter();
    private final int                       dp2      = SizeUtils.dp2px(2f);

    public static void start(Context context) {
        context.startActivity(new Intent(context, EditMinuteActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewBinding.titleBar.ivBack.setOnClickListener(v -> finish());
        viewBinding.titleBar.setTitle("锁机时间");
//        viewBinding.titleBar.setTvRight2("保存", v -> {
//            //
//        });

        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            boolean isLastItem = position == mAdapter.getData().size() - 1;
            // FIXME: 2024/12/1 只要不是会员, 每个item都要判断并弹窗!
            if (isLastItem) {   //自定义
                new VipBuyDialog(mActivity).show();
            } else {
                new IntEditDialog(mActivity, "修改分钟数", 1, number -> {
                    List<String> data = mAdapter.getData();
                    data.set(position, String.format("%02d分钟", number));
                    mAdapter.notifyItemChanged(position);
                }).show();
            }
        });
        viewBinding.recyclerView.addItemDecoration(new BaseItemDecoration(dp2 * 5, dp2 * 3));
        viewBinding.recyclerView.setAdapter(mAdapter);

        for (int i = 1; i < 13; i++) {
            mAdapter.addData(String.format("%02d分钟", i));
        }
        mAdapter.addData("自定义");
    }
}